<template>
	<view>
		<!-- <view class="getScanCode" @click="getScanCode">{{ btnName }}</view> -->
		<button class="mini-btn btn-style" type="primary" size="mini" @click="getScanCode">{{ btnName }}</button>
	</view>
</template>

<script>
	export default {
		name: "yt-scanCode",
		props: {
			btnName: {
				type: String,
				default: '扫码',
			}
		},

		data() {
			return {

			}
		},
		methods: {
			getScanCode() {
				uni.scanCode({
					onlyFromCamera: true,
					scanType: ['qrCode', 'barCode', 'dataMatrix'],
					success: res => {
						if(res.errMsg=='scanCode:ok'){
							console.log(JSON.stringify(res))
							this.$emit("getScanCode", res.result);
						}
						else
						{
							uni.showToast({
								title: '扫码失败',
								icon: "none",
								mask: true,
							})
						}
					},
					fail: err => {
						console.log(JSON.stringify(err))
					}

				})
			},

		}
	}
</script>

<style>
	.getScanCode {
		padding: 20rpx;
		box-sizing: border-box;
		/* height: 40rpx; */
		background-color: aqua;
		text-align: center;
		line-height: 40rpx;
	}
</style>